//
//  EditGuestInfoCell.m
//  QRMaster
//
//  Created by myApple on 16/4/28.
//  Copyright © 2016年 myApple. All rights reserved.
//

#import "EditGuestInfoCell.h"

@interface EditGuestInfoCell()<UITextFieldDelegate>
{
    UITextField * guestTextField;
}

@end

@implementation EditGuestInfoCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        //        btnToTimeId = [[NSMutableArray alloc]init];
        [self prepareView];
    }
    return self;
}

-(void)prepareView
{
    float x = 22;
    float y = 2;
    float width = UI_SCREEN_WIDTH - x - 16;
    float height = 40;
    
    guestTextField = [[UITextField alloc]initWithFrame:CGRectMake(x, y, width, height)];
    guestTextField.textColor = UIColorFromRGB(0x333333);
    guestTextField.placeholder = NSLocalizedString(@"input", nil);;
    guestTextField.font = [UIFont systemFontOfSize:16.0];
    guestTextField.delegate = self;
    [guestTextField addTarget:self action:@selector(textDidChange:) forControlEvents:UIControlEventEditingChanged];
    [self.contentView addSubview:guestTextField];
}

//-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
//{
//    BOOL flag = YES;//默认可以点击
//    NSString * newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
//    if ([newString isEqualToString:_guestNameString]) {
//        flag = NO;
//    }
//    else
//    {
//        flag = YES;
//    }
//    if (_delegate && [_delegate respondsToSelector:@selector(canSave:guestName:)]) {
//        [_delegate canSave:flag guestName:newString];
//    }
//    return YES;
//}


-(void)textDidChange:(UITextField *)textField
{
    BOOL flag = YES;//默认可以点击
    if ([textField.text isEqualToString:_guestNameString]) {
        flag = NO;
    }
    else
    {
        flag = YES;
    }
    if (_delegate && [_delegate respondsToSelector:@selector(canSave:guestName:)]) {
        [_delegate canSave:flag guestName:textField.text];
    }
}



-(void)setGuestNameString:(NSString *)guestNameString
{
    _guestNameString = guestNameString;
    guestTextField.text = guestNameString;
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
